package com.youlu.campus.web.data.english;

import com.youlu.campus.entity.english.vo.request.CompetitionCaCollectRequest;
import com.youlu.campus.service.english.UserCompetitionQaCaService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class UserCompetitionCaController {

    @Autowired
    private UserCompetitionQaCaService userCompetitionQaCaService;

    @GetMapping("/mini-app/competition/ca-list")
    public QResult caList() {
        return QResult.success(userCompetitionQaCaService.caList(RequestContext.getUserId()));
    }


    @PostMapping("/mini-app/competition/ca/collect")
    public QResult caCollect(@RequestBody @Validated CompetitionCaCollectRequest caCollectReq, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return QResult.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        caCollectReq.setCurrentUser(RequestContext.getCurUser());
        caCollectReq.setQaReceive(Boolean.TRUE);
        return QResult.success(userCompetitionQaCaService.caCollect(caCollectReq));
    }
}
